using System;
using System.Collections.Generic;
using Spring.Data;
using Spring.Transaction;
using Spring.Transaction.Interceptor;
using Com.Easywiki.Model;
using Common.Logging;
using NHibernate;
using Spring.Data.NHibernate.Generic;
using Spring.Data.NHibernate.Generic.Support;

namespace Com.Easywiki.DAO
{
	public interface IUserDAO{
		bool LoginCheck(string username, string password);
	}

	public class UserDAO : HibernateDaoSupport, IUserDAO{
		ILog log = LogManager.GetLogger("Ravi");
		public UserDAO (){	}

		public bool LoginCheck(string username, string password){
			Console.WriteLine("username->" + username);
			Console.WriteLine("password->" + password);

			//ICriteria criteria = CurrentSession.CreateCriteria<UserInfo>();

			IList<UserInfo> userlist = HibernateTemplate.Find<UserInfo>("from UserInfo u where u.Username='" +username + "' and password='" +password+"'");
			Console.WriteLine(userlist);
			if(userlist.Count > 0){
				Console.WriteLine("user count->"+userlist.Count);
				Console.WriteLine("in true.. login success");
				return true;
			}
			return false;
		}

		public override string ToString (){
			return string.Format ("[UserDAO: SessionFactory={0}, Session={1}]", SessionFactory, Session);
		}
	}
}